package com.dgut.smart_house.service.impl;

import com.dgut.smart_house.domain.Handle;
import com.dgut.smart_house.mapper.HandleMapper;
import com.dgut.smart_house.service.HandleService;
import com.dgut.smart_house.vo.HandleVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class HandleServiceImpl implements HandleService {

    @Autowired
    private HandleMapper handleMapper;

    @Override
    public void generateHandle(Handle handle) {

        handleMapper.generateHandle(handle);
    }

    @Override
    public void checkHandle(int handleId) {

        handleMapper.checkHandle(handleId);
    }

    @Override
    public PageInfo listUnHandled(int pageNo, int pageSize, int fromUser) {

        PageHelper.startPage(pageNo, pageSize);
        List<HandleVo> handleList = handleMapper.listUnHandled(fromUser);
        PageInfo<HandleVo> page = new PageInfo<HandleVo>(handleList);

        return page;
    }

    @Override
    public PageInfo listAllHandled(int pageNo, int pageSize, int fromUser) {
        PageHelper.startPage(pageNo, pageSize);
        List<HandleVo> handleList = handleMapper.listAllHandled(fromUser);
        for (int i = 0; i < handleList.size(); i++) {
            System.out.println(handleList.get(i).toString());
        }
        PageInfo<HandleVo> page = new PageInfo<HandleVo>(handleList);

        return page;
    }


    @Override
    public PageInfo listHandled(int pageNo, int pageSize, int fromUser) {
        PageHelper.startPage(pageNo, pageSize);
        List<HandleVo> handleList = handleMapper.listHandled(fromUser);
        PageInfo<HandleVo> page = new PageInfo<HandleVo>(handleList);

        return page;
    }

    @Override
    public Handle findHandleById(int handleId) {
        return handleMapper.findHandleById(handleId);
    }
}
